﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CocisDAL;

namespace CocisWeb.admin
{
    public partial class ManageLogs : System.Web.UI.Page
    {
        public LogsDAL logs = new LogsDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.txtDateStart.Text = DateTime.Now.AddDays(-7).ToShortDateString();
                this.txtDateEnd.Text = DateTime.Now.ToShortDateString();
                this.BindLogs();
            }
        }

        public void BindLogs()
        {
            DateTime  start= DateTime.Now.AddDays(-7);
            DateTime  end= DateTime.Now;
            this.gvRole.DataSource = logs.GetLogsInfo("",0,start,end);
            this.gvRole.DataBind();
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            DateTime start = DateTime.Parse(this.txtDateStart.Text); ;
            DateTime end = DateTime.Parse(this.txtDateEnd.Text);
            string user = this.txtUserName.Text;
            int type = int.Parse(this.ddlLogType.SelectedValue.ToString());
          
            this.gvRole.DataSource = logs.GetLogsInfo(user, type, start, end);
            this.gvRole.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.gvRole.Rows.Count; i++)
            {
                CheckBox cb = (CheckBox)this.gvRole.Rows[i].Cells[0].FindControl("CheckBox1");
                if (cb.Checked == true)
                {
                    int id = int.Parse(this.gvRole.Rows[i].Cells[1].Text);
                    int t = logs.DeleteLogsInfo(id);

                }
            }
            this.BindLogs();
        }

        protected void gvRole_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

       
    }
}
